package cn.itsource.org.service.Impl;

import cn.itsource.basic.service.Impl.BaseSerivcelmpl;
import cn.itsource.basic.util.PageList;
import cn.itsource.org.domain.Employee;
import cn.itsource.org.mapper.EmployeeMapper;
import cn.itsource.org.query.EmployeeQuery;
import cn.itsource.org.service.EmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl extends BaseSerivcelmpl<Employee, EmployeeQuery> implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void save(Employee employee) {
        employeeMapper.insertSelective(employee);
    }

    @Override
    public void update(Employee employee) {
        employeeMapper.updateByPrimaryKeySelective(employee);
    }

    @Override
    public void delete(Long id) {
        employeeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Employee> findAll() {

        return employeeMapper.selectAll();
    }

    @Override
    public Employee findOne(Long id) {
        return employeeMapper.selectOneByExample(id);
    }



    @Override
    public List<Employee> findManager() {
        return employeeMapper.findManager();
    }

    @Override
    public Employee checkRepeatEmployee(Employee admin) {
        return employeeMapper.checkRepeatEmployee(admin);
    }
    @Override
    public PageList<Employee> findPage(EmployeeQuery query) {
        //分页插件!!!!
        PageHelper.startPage(query.getPage(),query.getSize());
        List<Employee> page = employeeMapper.findPage(query);
        //封装到pageInfo
        PageInfo<Employee> info = new PageInfo<>(page);
        //封装自定义对象
        PageList<Employee> pageList = new PageList<>(info.getTotal(), info.getList());
        return pageList;
    }

}
